#include <iostream>
#include"concrete_colleague.h"
#include"concrete_mediator.h"
using namespace std;
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p) {delete(p); (p) = nullptr;} }
#endif
int main()
{
    // 房东
    IColleague *landlord = new ColleagueA("Tom");

    // 租客
    IColleague *jerry = new ColleagueA("Jerry");
    IColleague *tuffy = new ColleagueA("Tuffy");
    IColleague *tuffy2 = new ColleagueA("Meary");

    // 中介者 - 添加租客
    MediatorA mediator;
    mediator.registerColleague(jerry);
    mediator.registerColleague(tuffy);
    mediator.registerColleague(tuffy2);

    // 房东通过中介将消息发送出去
    landlord->sendMessage(mediator, "Xi'erqi, two bedroom house, 6000/month.");

    mediator.unRegisterColleague(tuffy);
    landlord->sendMessage(mediator, "Tian'anmen, three bedroom house, 2000/month.");

    SAFE_DELETE(jerry);
    SAFE_DELETE(tuffy);
    SAFE_DELETE(tuffy2);

    getchar();

    return 0;
}
